#include "config.hpp"
#include "pcb.hpp"
#include "rander.hpp"
#include "utility.hpp"
#include <array>
#include <iostream>

void func() {
  std::array<pcb<N_RESOURCE>, N_PROC> proc;
  std::array<size_t, N_RESOURCE> resources;
  init(proc, resources);
  print_init(proc, resources);
  is_safe(proc, resources);

  rander n_proc_rander(0, N_PROC - 1);
  size_t idx = n_proc_rander.get_rand();

  std::array<size_t, N_RESOURCE> request;
  std::cout << "P" << idx << " request: ";
  for (size_t i = 0; i < N_RESOURCE; ++i) {
    rander resource_rander(0, resources[i]);
    request[i] = resource_rander.get_rand();
    std::cout << request[i] << ' ';
  }
  std::cout << "\n";
  if (is_request_safe(idx, request, proc, resources)) {
    std::cout << "Request is safe!\n";

  } else {
    std::cout << "Request isn't safe!\n";
  }
}

int main() {
  func();
  return 0;
}